2000W / 48V LLC Battery-Charger  V1.00
xmc_rtc.c
Go to the documentation of this file.
1 
58 /*********************************************************************************************************************
59  * HEADER FILES
60  *********************************************************************************************************************/
61 
62 #include "xmc_scu.h"
63 #include "xmc_rtc.h"
64 
65 /*********************************************************************************************************************
66  * MACROS
67  *********************************************************************************************************************/
68 
69 #define XMC_RTC_MAXSECONDS (59U)
70 #define XMC_RTC_MAXMINUTES (59U)
71 #define XMC_RTC_MAXHOURS (23U)
72 #define XMC_RTC_MAXDAYS (31U)
73 #define XMC_RTC_MAXDAYSOFWEEK (7U)
74 #define XMC_RTC_MAXMONTH (12U)
75 #define XMC_RTC_MAXYEAR (0xFFFFU)
76 #define XMC_RTC_MAXPRESCALER (0xFFFFU)
77 #define XMC_RTC_YEAR_OFFSET (1900U)
79 #if (UC_FAMILY == XMC4)
80 #define XMC_RTC_INIT_SEQUENCE (1U)
81 #endif
82 #if (UC_FAMILY == XMC1)
83 #define XMC_RTC_INIT_SEQUENCE (0U)
84 #endif
85 
86 /*********************************************************************************************************************
87  * API IMPLEMENTATION
88  *********************************************************************************************************************/
89 
90 /*
91  * Enables RTC peripheral to start counting time
92  */
93 void XMC_RTC_Start(void)
94 {
96  {
97  /* check SCU_MIRRSTS to ensure that no transfer over serial interface is pending */
98  }
99  RTC->CTR |= (uint32_t)RTC_CTR_ENB_Msk;
100 }
101 
102 /*
103  * Disables RTC peripheral to start counting time
104  */
105 void XMC_RTC_Stop(void)
106 {
108  {
109  /* check SCU_MIRRSTS to ensure that no transfer over serial interface is pending */
110  }
111  RTC->CTR &= ~(uint32_t)RTC_CTR_ENB_Msk;
112 }
113 
114 /*
115  * Sets the RTC module prescaler value
116  */
117 void XMC_RTC_SetPrescaler(uint16_t prescaler)
118 {
119  XMC_ASSERT("XMC_RTC_SetPrescaler:Wrong prescaler value", (prescaler < XMC_RTC_MAXPRESCALER));
120 
122  {
123  /* check SCU_MIRRSTS to ensure that no transfer over serial interface is pending */
124  }
125  RTC->CTR = (RTC->CTR & ~(uint32_t)RTC_CTR_DIV_Msk) |
126  ((uint32_t)prescaler << (uint32_t)RTC_CTR_DIV_Pos);
127 }
128 
129 /*
130  * Sets the RTC_TIM0, RTC_TIM1 registers with time values
131  */
132 void XMC_RTC_SetTime(const XMC_RTC_TIME_t *const time)
133 {
134  XMC_ASSERT("XMC_RTC_SetTime:Wrong seconds value", ((uint32_t)time->seconds < XMC_RTC_MAXSECONDS));
135  XMC_ASSERT("XMC_RTC_SetTime:Wrong minutes value", ((uint32_t)time->minutes < XMC_RTC_MAXMINUTES));
136  XMC_ASSERT("XMC_RTC_SetTime:Wrong hours value", ((uint32_t)time->hours < XMC_RTC_MAXHOURS));
137  XMC_ASSERT("XMC_RTC_SetTime:Wrong month day value", ((uint32_t)time->days < XMC_RTC_MAXDAYS));
138  XMC_ASSERT("XMC_RTC_SetTime:Wrong week day value", ((uint32_t)time->daysofweek < XMC_RTC_MAXDAYSOFWEEK));
139  XMC_ASSERT("XMC_RTC_SetTime:Wrong month value", ((uint32_t)time->month < XMC_RTC_MAXMONTH));
140  XMC_ASSERT("XMC_RTC_SetTime:Wrong year value", ((uint32_t)time->year < XMC_RTC_MAXYEAR));
141 
142  #if (XMC_RTC_INIT_SEQUENCE == 1U)
144  {
145  /* check SCU_MIRRSTS to ensure that no transfer over serial interface is pending */
146  }
147  RTC->TIM0 = time->raw0;
148 
150  {
151  /* check SCU_MIRRSTS to ensure that no transfer over serial interface is pending */
152  }
153  RTC->TIM1 = time->raw1;
154  #endif
155  #if (XMC_RTC_INIT_SEQUENCE == 0U)
157  {
158  /* check SCU_MIRRSTS to ensure that no transfer over serial interface is pending */
159  }
160  RTC->TIM0 = time->raw0;
161  RTC->TIM1 = time->raw1; ;
162  #endif
163 }
164 
165 /*
166  * Gets the RTC module time value
167  */
169 {
170  time->raw0 = RTC->TIM0;
171  time->raw1 = RTC->TIM1;
172 }
173 
174 /*
175  * Sets the RTC module time values in standard format
176  */
177 void XMC_RTC_SetTimeStdFormat(const struct tm *const stdtime)
178 {
179 
180  XMC_RTC_TIME_t time;
181 
182  time.seconds = stdtime->tm_sec;
183  time.minutes = stdtime->tm_min;
184  time.hours = stdtime->tm_hour;
185  time.days = stdtime->tm_mday - 1;
186  time.month = stdtime->tm_mon;
187  time.year = stdtime->tm_year + XMC_RTC_YEAR_OFFSET;
188  time.daysofweek = stdtime->tm_wday;
189 
190  XMC_RTC_SetTime(&time);
191 }
192 
193 /*
194  * Gets the RTC module time values in standard format
195  */
196 void XMC_RTC_GetTimeStdFormat(struct tm *const stdtime)
197 {
198  XMC_RTC_TIME_t time;
199  time.raw0 = RTC->TIM0;
200  time.raw1 = RTC->TIM1;
201 
202  stdtime->tm_sec = (int8_t)time.seconds;
203  stdtime->tm_min = (int8_t)time.minutes;
204  stdtime->tm_hour = (int8_t)time.hours;
205  stdtime->tm_mday = ((int8_t)time.days + (int8_t)1);
206  stdtime->tm_mon = (int8_t)time.month;
207  stdtime->tm_year = (int32_t)time.year - (int32_t)XMC_RTC_YEAR_OFFSET;
208  stdtime->tm_wday = (int8_t)time.daysofweek;
209 }
210 
211 /*
212  * Sets the RTC module alarm time value
213  */
214 void XMC_RTC_SetAlarm(const XMC_RTC_ALARM_t *const alarm)
215 {
216  XMC_ASSERT("XMC_RTC_SetAlarm:Wrong seconds value", ((uint32_t)alarm->seconds < XMC_RTC_MAXSECONDS));
217  XMC_ASSERT("XMC_RTC_SetAlarm:Wrong minutes value", ((uint32_t)alarm->minutes < XMC_RTC_MAXMINUTES));
218  XMC_ASSERT("XMC_RTC_SetAlarm:Wrong hours value", ((uint32_t)alarm->hours < XMC_RTC_MAXHOURS));
219  XMC_ASSERT("XMC_RTC_SetAlarm:Wrong days value", ((uint32_t)alarm->days < XMC_RTC_MAXDAYS));
220  XMC_ASSERT("XMC_RTC_SetAlarm:Wrong month value", ((uint32_t)alarm->month < XMC_RTC_MAXMONTH));
221  XMC_ASSERT("XMC_RTC_SetAlarm:Wrong year value", ((uint32_t)alarm->year < XMC_RTC_MAXYEAR));
222 
223  #if (XMC_RTC_INIT_SEQUENCE == 1U)
225  {
226  /* check SCU_MIRRSTS to ensure that no transfer over serial interface is pending */
227  }
228  RTC->ATIM0 = alarm->raw0;
229 
231  {
232  /* check SCU_MIRRSTS to ensure that no transfer over serial interface is pending */
233  }
234  RTC->ATIM1 = alarm->raw1;
235  #endif
236  #if (XMC_RTC_INIT_SEQUENCE == 0U)
238  {
239  /* check SCU_MIRRSTS to ensure that no transfer over serial interface is pending */
240  }
241  RTC->ATIM0 = alarm->raw0;
242  RTC->ATIM1 = alarm->raw1;
243  #endif
244 }
245 
246 /*
247  * Gets the RTC module alarm time value
248  */
250 {
251  alarm->raw0 = RTC->ATIM0;
252  alarm->raw1 = RTC->ATIM1;
253 }
254 
255 
256 /*
257  * Sets the RTC module alarm time value in standard format
258  */
259 void XMC_RTC_SetAlarmStdFormat(const struct tm *const stdtime)
260 {
261  XMC_RTC_ALARM_t alarm;
262 
263 
264  alarm.seconds = stdtime->tm_sec;
265  alarm.minutes = stdtime->tm_min;
266  alarm.hours = stdtime->tm_hour;
267  alarm.days = stdtime->tm_mday - 1;
268  alarm.month = stdtime->tm_mon;
269  alarm.year = stdtime->tm_year + XMC_RTC_YEAR_OFFSET;
270 
271  XMC_RTC_SetAlarm(&alarm);
272 }
273 
274 /*
275  * Gets the RTC module alarm time value in standard format
276  */
277 void XMC_RTC_GetAlarmStdFormat(struct tm *const stdtime)
278 {
279  XMC_RTC_ALARM_t alarm;
280 
281  alarm.raw0 = RTC->ATIM0;
282  alarm.raw1 = RTC->ATIM1;
283 
284  stdtime->tm_sec = (int8_t)alarm.seconds;
285  stdtime->tm_min = (int8_t)alarm.minutes;
286  stdtime->tm_hour = (int8_t)alarm.hours;
287  stdtime->tm_mday = ((int8_t)alarm.days + (int8_t)1);
288  stdtime->tm_mon = (int8_t)alarm.month;
289  stdtime->tm_year = (int32_t)alarm.year - (int32_t)XMC_RTC_YEAR_OFFSET;
290 }
291 
292 /*
293  * Gets the RTC periodic and alarm event(s) status
294  */
296 {
297  return RTC->STSSR;
298 }
uint32_t hours
Definition: xmc_rtc.h:226
#define XMC_RTC_MAXMINUTES
Definition: xmc_rtc.c:70
void XMC_RTC_SetPrescaler(uint16_t prescaler)
Definition: xmc_rtc.c:117
#define RTC
Definition: XMC1400.h:8818
uint32_t month
Definition: xmc_rtc.h:240
uint32_t raw1
Definition: xmc_rtc.h:195
uint32_t minutes
Definition: xmc_rtc.h:184
uint32_t raw0
Definition: xmc_rtc.h:179
#define RTC_CTR_ENB_Msk
Definition: XMC1400.h:2048
void XMC_RTC_SetAlarm(const XMC_RTC_ALARM_t *const alarm)
Definition: xmc_rtc.c:214
#define SCU_GENERAL_MIRRSTS_RTC_TIM0_Msk
Definition: XMC1400.h:4036
uint32_t raw1
Definition: xmc_rtc.h:235
#define XMC_RTC_MAXMONTH
Definition: xmc_rtc.c:74
#define SCU_GENERAL_MIRRSTS_RTC_TIM1_Msk
Definition: XMC1400.h:4038
uint32_t year
Definition: xmc_rtc.h:242
#define XMC_ASSERT(msg, exp)
Definition: xmc_common.h:132
uint32_t hours
Definition: xmc_rtc.h:186
#define SCU_GENERAL_MIRRSTS_RTC_ATIM0_Msk
Definition: XMC1400.h:4032
uint32_t month
Definition: xmc_rtc.h:199
void XMC_RTC_SetAlarmStdFormat(const struct tm *const stdtime)
Definition: xmc_rtc.c:259
#define XMC_RTC_MAXDAYS
Definition: xmc_rtc.c:72
uint32_t raw0
Definition: xmc_rtc.h:219
#define RTC_CTR_DIV_Msk
Definition: XMC1400.h:2052
#define XMC_RTC_MAXSECONDS
RTC driver for XMC microcontroller family.
Definition: xmc_rtc.c:69
void XMC_RTC_GetTime(XMC_RTC_TIME_t *const time)
Definition: xmc_rtc.c:168
void XMC_RTC_Stop(void)
Definition: xmc_rtc.c:105
#define RTC_CTR_DIV_Pos
Definition: XMC1400.h:2051
void XMC_RTC_GetTimeStdFormat(struct tm *const stdtime)
Definition: xmc_rtc.c:196
uint32_t XMC_RTC_GetEventStatus(void)
Definition: xmc_rtc.c:295
void XMC_RTC_SetTime(const XMC_RTC_TIME_t *const time)
Definition: xmc_rtc.c:132
#define XMC_RTC_MAXYEAR
Definition: xmc_rtc.c:75
#define XMC_RTC_YEAR_OFFSET
Definition: xmc_rtc.c:77
uint32_t days
Definition: xmc_rtc.h:228
#define SCU_GENERAL_MIRRSTS_RTC_ATIM1_Msk
Definition: XMC1400.h:4034
void XMC_RTC_GetAlarm(XMC_RTC_ALARM_t *const alarm)
Definition: xmc_rtc.c:249
uint32_t seconds
Definition: xmc_rtc.h:182
void XMC_RTC_SetTimeStdFormat(const struct tm *const stdtime)
Definition: xmc_rtc.c:177
uint32_t daysofweek
Definition: xmc_rtc.h:238
__STATIC_INLINE uint32_t XMC_SCU_GetMirrorStatus(void)
Definition: xmc_scu.h:543
#define SCU_GENERAL_MIRRSTS_RTC_CTR_Msk
Definition: XMC1400.h:4030
void XMC_RTC_Start(void)
Definition: xmc_rtc.c:93
uint32_t year
Definition: xmc_rtc.h:201
uint32_t minutes
Definition: xmc_rtc.h:224
uint32_t seconds
Definition: xmc_rtc.h:222
#define XMC_RTC_MAXPRESCALER
Definition: xmc_rtc.c:76
#define XMC_RTC_MAXDAYSOFWEEK
Definition: xmc_rtc.c:73
#define XMC_RTC_MAXHOURS
Definition: xmc_rtc.c:71
void XMC_RTC_GetAlarmStdFormat(struct tm *const stdtime)
Definition: xmc_rtc.c:277
uint32_t days
Definition: xmc_rtc.h:188